<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>HuiCMF-后台登录</title>
    <link rel="stylesheet" href="__LIB__/pear/css/pear.css"/>
    <link rel="stylesheet" href="__STATIC_ADMIN__/style/login.css"/>
    <script>
      //全局变量
      var GV = {
        'site': {
          "upload_thumb_water": "0",
          "upload_thumb_water_pic": "",
          "upload_file_size": "0",
          "upload_file_ext": "",
          "chunking": false,
          "chunksize": "204800"
        },
        'upload_url': "",
      };
    </script>
</head>
<!-- 代 码 结 构 -->
<body background="__STATIC_ADMIN__/images/background.svg" style="background-size: cover;">
<form class="layui-form" action="javascript:void(0);" id="login">
    <div class="layui-form-item">
        <img class="logo" src="__STATIC_ADMIN__/images/logo.png"/>
        <div class="title">HuiCMF</div>
        <div class="desc">
            By WebMan
        </div>
    </div>
    <div class="layui-form-item">
        <input placeholder="账 户 : " lay-verify="required" name="username" hover class="layui-input"/>
    </div>
    <div class="layui-form-item">
        <input type="password" placeholder="密 码 : " lay-verify="required" name="password" hover class="layui-input"/>
    </div>

    {if $login_captcha ==1}
    <div class="layui-form-item">
        <input placeholder="验证码 : " hover lay-verify="required"
               class="code layui-input layui-input-inline" id="captcha" name="captcha" style="width:150px;"/>
        <input type="hidden" id="uniqId" name="uniqid">
        <img id="captcha_src" onclick="getCaptCha()" style="width:160px;float:right">
    </div>
    {/if}
    {if $login_captcha ==2}
    <div class="layui-form-item">
        <div id="c1"></div>
        <input type="hidden" name="captcha_token" id="captcha_token">
    </div>
    {/if}

    <div class="layui-form-item">
        <button class="pear-btn pear-btn-success login" lay-submit="" lay-filter="login">立即登录</button>
    </div>
</form>
<!-- 资 源 引 入 -->
{include file='footer'/}
<script src="https://cdn.dingxiang-inc.com/ctu-group/captcha-ui/index.js" crossorigin="anonymous"
        id="dx-captcha-script"></script>
<script>
  layui.use(['form', 'jquery'], function () {
    var $ = layui.jquery,
      form = layui.form,
      layer = layui.layer;
    form.render();

    let login_captcha = "{$login_captcha}";
    if (login_captcha == 1) {
      getCaptCha();
    }
    if (login_captcha == 2) {
      var myCaptcha = _dx.Captcha(document.getElementById('c1'), {
        appId: "{$dx_appId}",
        apiServer: "{$dx_apiurl}",
        style: 'oneclick', //inline 内联式，oneclick 触发式
        width: '320',
        success: function (token) {
          $('#captcha_token').val(token);
        }
      })
    }

    // 登录过期的时候，跳出ifram框架
    if (top.location != self.location) top.location = self.location;

    form.on('submit(login)', function (data) {
      if (login_captcha == 2) {
        let captcha_token = $('#captcha_token').val();
        if (captcha_token == '') {
          hui_msg('请先完成验证码的验证', 2)
          return false;
        }
      }
      $.post("{:__url('login/checkLogin')}", (data.field), function (res) {
        if (res.code === 200) {
          localStorage.setItem("hui-token", res.data.token);
          localStorage.setItem("adminInfo", JSON.stringify(res.data.admin_info));
          hui_msg(res.msg, 1, function () {
            location.href = '/admin/index'
          });
        } else {
          hui_msg(res.msg, 2, function () {
            if (login_captcha == 1) {
              getCaptCha();
              $('#captcha').val('');
            }
          })
        }
      })
    });

  });
</script>
</body>
</html>
